package com.matt.repository.impl;

import com.matt.foundation.DO.ChildListDO;
import com.matt.foundation.constant.CourseConstant;
import com.matt.repository.base.BaseNativeSqlRepository;
import com.matt.repository.base.ChildrenObservationRecordRepository;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/8/21
 * *******************************
 */
@Service
public class ChildrenObservationRecordRepositoryImpl extends BaseNativeSqlRepository implements ChildrenObservationRecordRepository {

    @Override
    public List<ChildListDO> findChildrenByPlan(String coursePlanId, Integer category, String childrenId) {
        String findChildrenSql = String.format("select c.id, c.name , c.imgUrl , c.gender" +
                        " from observation_new_record rr LEFT join children c on rr.childrenId = c.id " +
                        " WHERE  rr.category ='%s' ", category);

        findChildrenSql += String.format(" and rr.coursePlanClassesId = '%s'", coursePlanId);

        if (StringUtils.isNotBlank(childrenId)){
            findChildrenSql += String.format(" and c.id = '%s'", childrenId);
        }
        List<ChildListDO> objectArrayList = sqlObjectList(findChildrenSql, ChildListDO.class);
        return objectArrayList;
    }
}
